package com.tuanbiao.ui.setting;

import android.content.Context;
import android.content.Intent;

import com.tuanbiao.base.mvp.BasePresenterActivity;
import com.tuanbiao.controllers.SettingController;
import com.tuanbiao.databinding.ActivitySettingDeviceNumBinding;
import com.tuanbiao.models.SettingModel;
import com.tuanbiao.presenter.setting.SettingDeviceNumPresenter;

/**
 * @author abiao
 * @since 2022/5/11 17:16
 */
public class SettingDeviceNumActivity extends BasePresenterActivity<SettingDeviceNumPresenter, ActivitySettingDeviceNumBinding> implements SettingController.DeviceNumView {

    public static void start(Context context) {
        Intent starter = new Intent(context, SettingDeviceNumActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected ActivitySettingDeviceNumBinding getBindingView() {
        return ActivitySettingDeviceNumBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initView() {
        binding.ivToolbarBack.setOnClickListener(getBackListener());
        binding.btnReset.setOnClickListener(view -> {
            mPresenter.reset();
        });
        binding.btnCommit.setOnClickListener(view -> {
            mPresenter.changeNum(binding.scUse.isChecked(), getString(binding.etNum));
        });
    }

    @Override
    protected SettingDeviceNumPresenter createPresenter() {
        return new SettingDeviceNumPresenter(new SettingModel(), this);
    }


    @Override
    public void showDeviceNum(String num, boolean enable) {
        binding.etNum.setText(num);
        binding.scUse.setChecked(enable);
    }
}